package com.alibaba.citrus.ots.platform.enhance.facade.service;

import java.util.List;

import javax.annotation.Resource;

import com.alibaba.citrus.ots.common.annotation.FacadeInvoker;
import com.alibaba.citrus.ots.platform.enhance.repository.CustomerRepository;
import com.alibaba.cz.base.tool.page.PageResult;
import com.alibaba.lattice2.epoch.sdk.model.Result;

import com.epoch.app.otsplatformenhance.api.customerquery.service.CustomerQueryService;
import com.epoch.app.otsplatformenhance.dto.request.CustomerBatchRequest;
import com.epoch.app.otsplatformenhance.dto.request.CustomerRequest;
import com.epoch.app.otsplatformenhance.dto.request.QueryCustomerRequest;
import com.epoch.app.otsplatformenhance.sdo.CustomerSDO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

@Primary
@Service
public class CustomerQueryServiceImpl implements CustomerQueryService {

    @Resource
    private CustomerRepository customerRepository;

    @Override
    @FacadeInvoker
    public Result<CustomerSDO> queryCustomer(CustomerRequest customerRequest) {
        CustomerSDO result = customerRepository.query(customerRequest);
        return Result.success(result);
    }

    @Override
    @FacadeInvoker
    public Result<List<CustomerSDO>> batchQueryCustomer(CustomerBatchRequest request) {
        List<CustomerSDO> response = customerRepository.batchQuery(request);
        return Result.success(response);
    }

    @Override
    @FacadeInvoker
    public Result<List<CustomerSDO>> pageQueryCustomer(QueryCustomerRequest request) {
        PageResult<List<CustomerSDO>> customerList = customerRepository.pageQuery(request);
        return Result.listSuccess(customerList.getContent(), customerList.getTotal());
    }
}
